package com.fg.pro.trade.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.trade.entity.TradeOrder;
import com.fg.pro.trade.service.TradeOrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 订单(TradeOrder)表控制层
 *
 * @author makejava
 * @since 2025-08-17 10:01:50
 */
@RestController
@RequestMapping("tradeOrder")
public class TradeOrderController {
    /**
     * 服务对象
     */
    @Resource
    private TradeOrderService tradeOrderService;

    @Operation(summary = "刷新订单信息",description = "参数时间，可以不传参，默认刷新时间当前")
    @PostMapping("/refresh")
    public ResponseResult refresh(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                  @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) throws InterruptedException {
        boolean flag = tradeOrderService.refresh(start,end);
        return ResponseResult.okResult(flag?"刷新成功":"正在刷新中。。。");
    }

    @Operation(summary = "获取订单分页",description = "")
    @GetMapping("/getPage")
    public ResponseResult getPage(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                  @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                  @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end,
                                  @RequestParam(required = false)String orderCode,
                                  @RequestParam(required = false)String selectType){
        PageInfo pageInfo = tradeOrderService.getPage(pageNum,pageSize,start,end,orderCode,selectType);
        return ResponseResult.okResult(pageInfo);
    }

}

